.class Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;
.super Landroid/database/sqlite/SQLiteOpenHelper;
.source "SQLiteCookieStorage.java"


# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0xa
    name = "CookiePersistanceManager"
.end annotation


# static fields
.field private static final COOKIE_DB_NAME:Ljava/lang/String; = "cookiedb"

.field private static final COOKIE_TABLE_CREATE:Ljava/lang/String; = "CREATE TABLE cookie (name  TEXT PRIMARY KEY, cookie_content TEXT, expires INTEGER);"

.field private static final DATABASE_VERSION:I = 0x2

.field private static final EXIST_COOKIE_SQL:Ljava/lang/String; = "SELECT name FROM cookie WHERE name=?"

.field static final TABLE_NAME:Ljava/lang/String; = "cookie"


# instance fields
.field final mWritableDatabase:Landroid/database/sqlite/SQLiteDatabase;


# direct methods
.method constructor <init>(Landroid/content/Context;)V
    .locals 4
    .parameter "context"

    .prologue
    .line 204
    invoke-virtual {p1}, Landroid/content/Context;->getApplicationContext()Landroid/content/Context;

    move-result-object v0

    const-string v1, "cookiedb"

    const/4 v2, 0x0

    const/4 v3, 0x2

    invoke-direct {p0, v0, v1, v2, v3}, Landroid/database/sqlite/SQLiteOpenHelper;-><init>(Landroid/content/Context;Ljava/lang/String;Landroid/database/sqlite/SQLiteDatabase$CursorFactory;I)V

    .line 205
    invoke-virtual {p0}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->getWritableDatabase()Landroid/database/sqlite/SQLiteDatabase;

    move-result-object v0

    iput-object v0, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->mWritableDatabase:Landroid/database/sqlite/SQLiteDatabase;

    .line 206
    return-void
.end method


# virtual methods
.method beginTransaction()V
    .locals 1

    .prologue
    .line 224
    iget-object v0, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->mWritableDatabase:Landroid/database/sqlite/SQLiteDatabase;

    invoke-virtual {v0}, Landroid/database/sqlite/SQLiteDatabase;->beginTransaction()V

    .line 225
    return-void
.end method

.method commit()V
    .locals 1

    .prologue
    .line 231
    iget-object v0, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->mWritableDatabase:Landroid/database/sqlite/SQLiteDatabase;

    invoke-virtual {v0}, Landroid/database/sqlite/SQLiteDatabase;->setTransactionSuccessful()V

    .line 232
    iget-object v0, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->mWritableDatabase:Landroid/database/sqlite/SQLiteDatabase;

    invoke-virtual {v0}, Landroid/database/sqlite/SQLiteDatabase;->endTransaction()V

    .line 233
    return-void
.end method

.method deleteAll()V
    .locals 6

    .prologue
    const/4 v5, 0x0

    const/4 v4, 0x0

    .line 324
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->access$000()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v0

    const-string v1, "SQLiteCookieStorage"

    const-string v2, "Deleting all cookies from DB..."

    new-array v3, v4, [Ljava/lang/Object;

    invoke-virtual {v0, v1, v2, v3}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 325
    iget-object v0, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->mWritableDatabase:Landroid/database/sqlite/SQLiteDatabase;

    const-string v1, "cookie"

    invoke-virtual {v0, v1, v5, v5}, Landroid/database/sqlite/SQLiteDatabase;->delete(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)I

    .line 326
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->access$000()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v0

    const-string v1, "SQLiteCookieStorage"

    const-string v2, "All cookies are deleted."

    new-array v3, v4, [Ljava/lang/Object;

    invoke-virtual {v0, v1, v2, v3}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 327
    return-void
.end method

.method deleteCookie(Ljava/lang/String;)V
    .locals 6
    .parameter "cookieName"

    .prologue
    const/4 v5, 0x1

    const/4 v4, 0x0

    .line 313
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->access$000()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v0

    const-string v1, "SQLiteCookieStorage"

    const-string v2, "Deleting \'\'{0}\'\' cookie from DB..."

    new-array v3, v5, [Ljava/lang/Object;

    aput-object p1, v3, v4

    invoke-virtual {v0, v1, v2, v3}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 314
    iget-object v0, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->mWritableDatabase:Landroid/database/sqlite/SQLiteDatabase;

    const-string v1, "cookie"

    const-string v2, "name=?"

    new-array v3, v5, [Ljava/lang/String;

    aput-object p1, v3, v4

    invoke-virtual {v0, v1, v2, v3}, Landroid/database/sqlite/SQLiteDatabase;->delete(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)I

    .line 317
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->access$000()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v0

    const-string v1, "SQLiteCookieStorage"

    const-string v2, "Cookie \'\'{0}\'\' deleted."

    new-array v3, v5, [Ljava/lang/Object;

    aput-object p1, v3, v4

    invoke-virtual {v0, v1, v2, v3}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 318
    return-void
.end method

.method exists(Ljava/lang/String;)Z
    .locals 6
    .parameter "cookieName"

    .prologue
    .line 294
    iget-object v2, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->mWritableDatabase:Landroid/database/sqlite/SQLiteDatabase;

    const-string v3, "SELECT name FROM cookie WHERE name=?"

    const/4 v4, 0x1

    new-array v4, v4, [Ljava/lang/String;

    const/4 v5, 0x0

    aput-object p1, v4, v5

    invoke-virtual {v2, v3, v4}, Landroid/database/sqlite/SQLiteDatabase;->rawQuery(Ljava/lang/String;[Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v0

    .line 297
    .local v0, cursor:Landroid/database/Cursor;
    const/4 v1, 0x0

    .line 298
    .local v1, result:Z
    if-eqz v0, :cond_0

    .line 299
    invoke-interface {v0}, Landroid/database/Cursor;->moveToFirst()Z

    move-result v1

    .line 300
    invoke-interface {v0}, Landroid/database/Cursor;->isClosed()Z

    move-result v2

    if-nez v2, :cond_0

    .line 301
    invoke-interface {v0}, Landroid/database/Cursor;->close()V

    .line 304
    :cond_0
    return v1
.end method

.method getSavedCookies()Ljava/util/List;
    .locals 8
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "()",
            "Ljava/util/List",
            "<",
            "Lcom/burstly/lib/network/beans/cookie/CookieTO;",
            ">;"
        }
    .end annotation

    .prologue
    const/4 v7, 0x0

    .line 266
    new-instance v0, Ljava/util/ArrayList;

    invoke-direct {v0}, Ljava/util/ArrayList;-><init>()V

    .line 267
    .local v0, cookies:Ljava/util/List;,"Ljava/util/List<Lcom/burstly/lib/network/beans/cookie/CookieTO;>;"
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->access$000()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v2

    const-string v3, "SQLiteCookieStorage"

    const-string v4, "Loading cookies from DB..."

    new-array v5, v7, [Ljava/lang/Object;

    invoke-virtual {v2, v3, v4, v5}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 268
    iget-object v2, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->mWritableDatabase:Landroid/database/sqlite/SQLiteDatabase;

    const-string v3, "SELECT name, cookie_content, expires FROM cookie"

    const/4 v4, 0x0

    invoke-virtual {v2, v3, v4}, Landroid/database/sqlite/SQLiteDatabase;->rawQuery(Ljava/lang/String;[Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object v1

    .line 270
    .local v1, cursor:Landroid/database/Cursor;
    if-eqz v1, :cond_2

    .line 271
    invoke-interface {v1}, Landroid/database/Cursor;->moveToFirst()Z

    move-result v2

    if-eqz v2, :cond_1

    .line 273
    :cond_0
    new-instance v2, Lcom/burstly/lib/network/beans/cookie/CookieTO;

    invoke-interface {v1, v7}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v3

    const/4 v4, 0x1

    invoke-interface {v1, v4}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object v4

    const/4 v5, 0x2

    invoke-interface {v1, v5}, Landroid/database/Cursor;->getLong(I)J

    move-result-wide v5

    invoke-static {v5, v6}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v5

    invoke-direct {v2, v3, v4, v5}, Lcom/burstly/lib/network/beans/cookie/CookieTO;-><init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;)V

    invoke-interface {v0, v2}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 274
    invoke-interface {v1}, Landroid/database/Cursor;->moveToNext()Z

    move-result v2

    if-nez v2, :cond_0

    .line 275
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->access$000()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v2

    const-string v3, "SQLiteCookieStorage"

    const-string v4, "Cookies were successfully loaded from DB."

    new-array v5, v7, [Ljava/lang/Object;

    invoke-virtual {v2, v3, v4, v5}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 277
    :cond_1
    invoke-interface {v1}, Landroid/database/Cursor;->isClosed()Z

    move-result v2

    if-nez v2, :cond_2

    .line 278
    invoke-interface {v1}, Landroid/database/Cursor;->close()V

    .line 281
    :cond_2
    invoke-interface {v0}, Ljava/util/List;->isEmpty()Z

    move-result v2

    if-eqz v2, :cond_3

    .line 282
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->access$000()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v2

    const-string v3, "SQLiteCookieStorage"

    const-string v4, "No saved cookies in DB."

    new-array v5, v7, [Ljava/lang/Object;

    invoke-virtual {v2, v3, v4, v5}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 284
    :cond_3
    return-object v0
.end method

.method public onCreate(Landroid/database/sqlite/SQLiteDatabase;)V
    .locals 1
    .parameter "sqlitedatabase"

    .prologue
    .line 210
    const-string v0, "CREATE TABLE cookie (name  TEXT PRIMARY KEY, cookie_content TEXT, expires INTEGER);"

    invoke-virtual {p1, v0}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V

    .line 211
    return-void
.end method

.method public onUpgrade(Landroid/database/sqlite/SQLiteDatabase;II)V
    .locals 6
    .parameter "sqlitedatabase"
    .parameter "i"
    .parameter "j"

    .prologue
    .line 215
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->access$000()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v0

    const-string v1, "SQLiteCookieStorage"

    const-string v2, "Upgrading database from version {0} to {1}, which will destroy all old data"

    const/4 v3, 0x2

    new-array v3, v3, [Ljava/lang/Object;

    const/4 v4, 0x0

    invoke-static {p2}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v5

    aput-object v5, v3, v4

    const/4 v4, 0x1

    invoke-static {p3}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v5

    aput-object v5, v3, v4

    invoke-virtual {v0, v1, v2, v3}, Lcom/burstly/lib/util/LoggerExt;->logWarning(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 216
    const-string v0, "DROP TABLE IF EXISTS cookie"

    invoke-virtual {p1, v0}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V

    .line 217
    invoke-virtual {p0, p1}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->onCreate(Landroid/database/sqlite/SQLiteDatabase;)V

    .line 218
    return-void
.end method

.method saveOrUpdateCookie(Lcom/burstly/lib/network/beans/cookie/CookieHolder;ZJ)V
    .locals 9
    .parameter "cookie"
    .parameter "insert"
    .parameter "expires"

    .prologue
    const/4 v8, 0x1

    const/4 v7, 0x0

    .line 243
    invoke-static {p1}, Lcom/burstly/lib/util/Utils;->toJson(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v0

    .line 244
    .local v0, cookieContent:Ljava/lang/String;
    invoke-virtual {p1}, Lcom/burstly/lib/network/beans/cookie/CookieHolder;->getName()Ljava/lang/String;

    move-result-object v1

    .line 245
    .local v1, name:Ljava/lang/String;
    new-instance v2, Landroid/content/ContentValues;

    invoke-direct {v2}, Landroid/content/ContentValues;-><init>()V

    .line 246
    .local v2, values:Landroid/content/ContentValues;
    const-string v3, "name"

    invoke-virtual {v2, v3, v1}, Landroid/content/ContentValues;->put(Ljava/lang/String;Ljava/lang/String;)V

    .line 247
    const-string v3, "cookie_content"

    invoke-virtual {v2, v3, v0}, Landroid/content/ContentValues;->put(Ljava/lang/String;Ljava/lang/String;)V

    .line 248
    const-string v3, "expires"

    invoke-static {p3, p4}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v4

    invoke-virtual {v2, v3, v4}, Landroid/content/ContentValues;->put(Ljava/lang/String;Ljava/lang/Long;)V

    .line 249
    if-nez p2, :cond_0

    .line 250
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->access$000()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v3

    const-string v4, "SQLiteCookieStorage"

    const-string v5, "Updating cookie {0}"

    new-array v6, v8, [Ljava/lang/Object;

    aput-object p1, v6, v7

    invoke-virtual {v3, v4, v5, v6}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 251
    iget-object v3, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->mWritableDatabase:Landroid/database/sqlite/SQLiteDatabase;

    const-string v4, "cookie"

    const-string v5, "name=?"

    new-array v6, v8, [Ljava/lang/String;

    aput-object v1, v6, v7

    invoke-virtual {v3, v4, v2, v5, v6}, Landroid/database/sqlite/SQLiteDatabase;->update(Ljava/lang/String;Landroid/content/ContentValues;Ljava/lang/String;[Ljava/lang/String;)I

    .line 258
    :goto_0
    return-void

    .line 255
    :cond_0
    invoke-static {}, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage;->access$000()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v3

    const-string v4, "SQLiteCookieStorage"

    const-string v5, "Saving cookie {0}"

    new-array v6, v8, [Ljava/lang/Object;

    aput-object p1, v6, v7

    invoke-virtual {v3, v4, v5, v6}, Lcom/burstly/lib/util/LoggerExt;->logDebug(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 256
    iget-object v3, p0, Lcom/burstly/lib/network/beans/cookie/SQLiteCookieStorage$CookiePersistanceManager;->mWritableDatabase:Landroid/database/sqlite/SQLiteDatabase;

    const-string v4, "cookie"

    const/4 v5, 0x0

    invoke-virtual {v3, v4, v5, v2}, Landroid/database/sqlite/SQLiteDatabase;->insert(Ljava/lang/String;Ljava/lang/String;Landroid/content/ContentValues;)J

    goto :goto_0
.end method
